home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFcolours / c / SFCCreateFile < prev    next >
Encoding:
Text File  |  2003-10-24  |  4.2 KB  |  129 lines

  1. /*
  2.  *  SFcolours - Star Fighter 3000 colours editor
  3.  *  Colours file creation dbox
  4.  *  Copyright (C) 2001  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. /* RISC OS library files */
  27. #include "wimp.h"
  28. #include "toolbox.h"
  29. #include "event.h"
  30. #include "wimplib.h"
  31. #include "window.h"
  32. #include "gadgets.h"
  33. #include "flex.h"
  34.  
  35. /* My library files */
  36. #include "err.h"
  37. #include "msgtrans.h"
  38. #include "Macros.h"
  39. #include "NoBudge.h"
  40. #include "InputFocus.h"
  41.  
  42. /* Local headers */
  43. #include "EditColmap.h"
  44. #include "Utils.h"
  45. #include "SFCCreateFile.h"
  46.  
  47. /* Gadget Ids */
  48. #define CREATEFILE_MAKECOLS 0x00
  49. #define CREATEFILE_MAKEHILL 0x01
  50. #define CREATEFILE_CANCEL   0x02
  51. #define CREATEFILE_CREATE   0x03
  52.  
  53. ObjectId CreateFile_sharedid = NULL_ObjectId;
  54. static int radiosel;
  55.  
  56. /* ----------------------------------------------------------------------- */
  57. /*                       Function prototypes                               */
  58.  
  59. static ToolboxEventHandler _CreateFile_clickhandler;
  60.  
  61. /* ----------------------------------------------------------------------- */
  62. /*                         Public functions                                */
  63.  
  64. void CreateFile_initialise(ObjectId id)
  65. {
  66.   /* Record ID */
  67.   CreateFile_sharedid = id;
  68.  
  69.   /* Register event handlers */
  70.   EF(event_register_toolbox_handler(id, ActionButton_Selected, _CreateFile_clickhandler, NULL));
  71.   EF(event_register_toolbox_handler(id, Window_AboutToBeShown, InputFocus_recordcaretpos, NULL));
  72.   
  73.   /* Store initial state of dbox */
  74.   EF(radiobutton_get_state(0, id, CREATEFILE_MAKECOLS, NULL, &radiosel));
  75. }
  76.  
  77. /* ----------------------------------------------------------------------- */
  78. /*                         Private functions                               */
  79.  
  80. static int _CreateFile_clickhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  81. {
  82.   switch(id_block->self_component) {
  83.  
  84.     case CREATEFILE_CREATE: {
  85.       void *new_cols;
  86.       E_RETV(radiobutton_get_state(0, id_block->self_id, CREATEFILE_MAKECOLS, NULL, &radiosel), 1);
  87.     
  88.       switch(radiosel) {
  89.         case CREATEFILE_MAKECOLS:
  90.           /* Create a new colours file */
  91.           if(!flex_alloc((flex_ptr)&new_cols, sizeof(SF_ColourMap)))
  92.             MG_RETV("NoMem", 1); /* claim event */
  93.           nobudge_register(256);
  94.           memset(new_cols, 0, sizeof(SF_ColourMap));
  95.           nobudge_deregister();
  96.     
  97.           /* Initialise static colours */
  98.           for(int staticcol = 0; staticcol < 256; staticcol++)
  99.             ((SF_ColourMap *)new_cols)->areas.static_colours[staticcol] = staticcol;
  100.           break;
  101.     
  102.         case CREATEFILE_MAKEHILL:
  103.           /* Create a new hill colours file */
  104.           if(!flex_alloc((flex_ptr)&new_cols, sizeof(SF_HillCols)))
  105.             MG_RETV("NoMem", 1); /* claim event */
  106.           nobudge_register(256);
  107.           memset(new_cols, 0, sizeof(SF_HillCols));
  108.           nobudge_deregister();
  109.           break;
  110.       }
  111.     
  112.       ObjectId editing_win = EditColmap_create((flex_ptr)&new_cols, (radiosel == CREATEFILE_MAKEHILL), "<untitled>", 0);
  113.       if(editing_win == NULL)
  114.         flex_free((flex_ptr)&new_cols);
  115.       else
  116.         RE(toolbox_show_object(0, editing_win, Toolbox_ShowObject_Centre, NULL, id_block->self_id, NULL_ComponentId))
  117.  
  118.       } return 1; /* claim event */
  119.       
  120.     case CREATEFILE_CANCEL:
  121.       /* Reset dbox state */
  122.       RE(radiobutton_set_state(0, id_block->self_id, radiosel, 1))
  123.       return 1; /* claim event */
  124.       
  125.     default:
  126.       return 0; /* unknown button */
  127.   }
  128. }
  129.